package com.aistar.service.Impl;

import com.aistar.mapper.ProjectExperienceMapper;
import com.aistar.pojo.ProjectExperience;
import com.aistar.pojo.ProjectExperienceExample;
import com.aistar.service.ProjectExperienceService;
import com.aistar.util.ServerResponse;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProjectExperienceServiceImpl implements ProjectExperienceService {
    @Autowired
    private ProjectExperienceMapper projectExperienceMapper;
    @Override
    public ServerResponse add(ProjectExperience projectExperience) {

        int rows = projectExperienceMapper.insert(projectExperience);
        if(rows >0)
            return ServerResponse.addSuccess();
        return ServerResponse.addFailed();

    }

    @Override
    public ServerResponse modify(ProjectExperience projectExperience) {

        int rows = projectExperienceMapper.updateByPrimaryKeySelective(projectExperience);

        if (rows>0)
            return ServerResponse.updateSuccess();
        return ServerResponse.updateFailed();
    }

    @Override
    public ServerResponse modifyStatus(ProjectExperience projectExperience) {
        return null;
    }

    @Override
    public ServerResponse getById(Integer id) {

        ProjectExperience experience = projectExperienceMapper.selectByPrimaryKey(id);

        if(experience !=null)
            return ServerResponse.getDateSuccess(experience);
        return ServerResponse.getDataFailed("没有该项目经验");
    }

    @Override
    public ServerResponse getAll() {
        return null;
    }

    @Override
    public ServerResponse getAllByResumeId(Integer resumeId) {

        ProjectExperienceExample experienceExample = new ProjectExperienceExample();

        experienceExample.createCriteria().andResumeIdEqualTo(resumeId).andStatusEqualTo(0);

        List<ProjectExperience> projectExperienceList =  projectExperienceMapper.selectByExample(experienceExample);
        if(projectExperienceList!=null && projectExperienceList.size() >0)
            return ServerResponse.getDateSuccess(projectExperienceList);
        return ServerResponse.getDataFailed("暂无项目经验");
    }

    public ServerResponse getLatestByResumeId(Integer resumeId) {

        ProjectExperienceExample example =  new ProjectExperienceExample();
        example.createCriteria().andResumeIdEqualTo(resumeId).andStatusEqualTo(0);
        example.setOrderByClause("project_experi_id desc");
        ProjectExperience experience = projectExperienceMapper.selectByExample(example).get(0);
        return ServerResponse.getDateSuccess(experience);
    }
}
